/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package phan.connection;
import java.util.*;
import phan.connection.MySQLDBConnector;
/**
 *
 * @author BAILLEURS SERVICES
 */


public class LoginBean {

    private String user;
    private String pass;
    private Hashtable errors;

    public  LoginBean(){
       user="";
       pass="";
       errors = new Hashtable();
    }


   public boolean validate() {
System.out.print(user+pass);
        boolean allOk = true;

        if (user.equals("")) {
            errors.put("user"," Veuillez saisir votre Pseudo svp  ");
            user="";
            allOk = false;
        }
        if (pass.equals("")) {
            errors.put("pass","Veuillez saisir votre password svp");
            pass="";
            allOk = false;
        }
        if(!user.equals("")&&!pass.equals("")){
            if(checkLogin(user,pass)==0){
            errors.put("user","Veuillez  vérifier votre Pseudo svp ");
            user="";
            pass="";
            allOk=false;}
        }
        if(checkLogin(user,pass)==4){
            
            errors.put("user","Veuillez activer votre compte svp");
            user="";
            pass="";
            allOk=false;
        }
      return allOk;
   }

   public int checkLogin(String user, String pass){
       int valide=0;
       MySQLDBConnector con=new MySQLDBConnector();
       valide=con.checkUser(user, pass);
       return valide;
   }
    /**
     * @return the user
     */
    public String getUser() {
        return user;
    }

    /**
     * @param user the user to set
     */
    public void setUser(String user) {
        this.user = user;
    }

    /**
     * @return the pass
     */
    public String getPass() {
        return pass;
    }

    /**
     * @param pass the pass to set
     */
    public void setPass(String pass) {
        this.pass = pass;
    }

    public String getErrorMsg(String s) {
        String errorMsg = (String) getErrors().get(s.trim());
        return (errorMsg == null) ? "" : errorMsg;
    }

     /**
     * @return the errors
     */
    public Hashtable getErrors() {
        return errors;
    }

    /**
     * @param errors the errors to set
     */
    public void setErrors(Hashtable errors) {
        this.errors = errors;

    }

}
